#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
int n,m,a[MAXN],l[MAXN<<1],r[MAXN<<1],p,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]<m)a[i]=-1;
		else if(a[i]>m)a[i]=1;
		else p=i,a[i]=0;
	}
	for(int i=1;i<=n;++i)a[i]+=a[i-1];
	for(int i=0;i<p;++i)++l[a[i]+n];
	for(int i=p;i<=n;++i)++r[a[i]+n];
	for(int i=0;i<=2*n;++i)ans+=(l[i]*r[i]);
	printf("%d\n",ans);
	return 0;
}
